/*
	GameServer.h

	This object is used to route verbs for one or more clients
	(c)1999 Palestar Development, Richard Lyle
*/

#ifndef GAME_SERVER_H
#define GAME_SERVER_H

#include "World/WorldServer.h"
#include "GameContext.h"
#include "GameDll.h"

//----------------------------------------------------------------------------

class DLL GameServer : public WorldServer, public GameContext::GameUser
{
public:
	DECLARE_WIDGET_CLASS();

	// Construction
	GameServer();

	// WorldServer interface
	virtual dword		version() const;								// get the server version, must match the client version..
	virtual Profile *	createProfile();
	virtual bool		addPlayerProfile( dword nUserId, const char * pField, float fAmount );
	virtual bool		publishServer();								// send updated information back to the MetaServer
	virtual bool		prepWorld();
	virtual bool		cleanWorld();

	virtual bool		canJoinTeam( ClientContext & client, int nTeamId );
	virtual bool		canSpawn( ClientContext & context, Noun * pSpawnPoint, Noun * pSpawn,
							Array< Noun::Ref > & Storage );
	virtual bool		onSpawn( ClientContext & context, Noun * pSpawnPoint, Noun * pSpawn, bool bNewSpawn );
	virtual void		onDeleteClient( ClientContext & client );
	virtual bool		onStorageLoaded( UserStorage * a_pStorage );

	// GameServerCommand.cpp
	virtual bool		processCommand( ClientContext & context, const char * pChat );

	// WorldContext::User interface
	virtual void		onAttachNoun( Noun * pNoun );
	virtual void		onDetachNoun( Noun * pNoun );
	virtual void		onCondition( int conditionId );					// called when a condition is true
	virtual bool		saveStorage( Noun * a_pSelf );

	// GameContext::GameUser interface
	void				onKill( Noun * pWho, Noun *pDead );
	void				onDestroyed( NounShip * pWho, Noun * pKiller );
	void				onDamageShip( Noun * pWho, float damage , Noun *pTarget);
	void				onCaptureShip( Noun * pWho, NounShip * pCaptured );
	void				onFriendlyFire( Noun * pWho, float damage );
	void				onPlanetsDamaged( Noun * pWho, float damage );
	void				onPlanetsCaptured( Noun * pWho, float amount );
	void				onRepair( Noun * pWho, float repair );
	void				onConstruct( Noun * pWho, float construct );
	void				onKamikaze( Noun * pWho, float damage );
	void				onSelfDestruct( NounShip * pWho );
	void				onJump( Noun * pWho );
	void				onCollidePlanet( Noun * pWho );
	void				onResourcesLost( Noun * pWho, float amount );
	void				onScout( Noun * pWho, float points );
	void				onBonusPrestige( Noun * pWho, float bonus );
	void				onCredits( Noun * pWho, int credits );

	void				onOrderReceived( NounShip * pWho, NounShip::Order order, 
							Noun * pTarget, Noun * pFrom );

	// Accessors
	GameContext *		gameContext() const;
	
	// Mutators
	bool				addProfile( Noun * pTarget,	Statistics nStat, float fValue );
	bool				addProfile( dword nUserId, Statistics nStat, float fValue );

	int					getStorageCargoCount( dword nUserId );
	bool				auditShip( NounShip * a_pShip, NounShip * a_pShipTemplate );
};

//---------------------------------------------------------------------------------------------------

inline GameContext * GameServer::gameContext() const
{
	return (GameContext *)worldContext();
}

//-------------------------------------------------------------------------------

#endif

//----------------------------------------------------------------------------
// EOF
